<template>
    <div>
        <h3>房型添加</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房型名称</td>
                    <td><input type="text" v-model="a.HouseTypeName"></td>
                </tr>
                <tr>
                    <td>图片</td>
                    <td><input type="file" @change="imgs">
                        <img :src="a.Photo" width="200">
                    </td>
                </tr>
                <tr>
                    <td>面积</td>
                    <td><input type="text" v-model="a.Area"></td>
                </tr>
                <tr>
                    <td>是否有窗户</td>
                    <td><input type="radio" v-model="a.IsWindow" :value="1" name="win">有
                        <input type="radio" v-model="a.IsWindow" :value="0" name="win">没有
                    </td>
                </tr>
                <tr>
                    <td>可住人数</td>
                    <td><input type="text" v-model="a.Count"></td>
                </tr>
                <tr>
                    <td>价格</td>
                    <td><input type="text" v-model="a.Price"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import axios from 'axios';
import moment from 'moment';
const router = useRouter();
const route = useRoute();

let a: any = reactive({
    HouseTypeName: '',
    Photo: '',
    Area: '',
    IsWindow: 1,
    Count: '',
    Price: '',
    State: 1,

})


const imgs: any = (e: any) => {
    let obj = e.target.files[0];
    let f = new FormData();
    f.append('file', obj);
    axios({
        method: 'post',
        url: '/api/Imgs/UpImg',
        data: f
    })
        .then((res) => {
            console.log(res);
            a.Photo = res.data
        })
}

const ok:any=()=>{
    axios({
        url:'/api/HouseType/HouseAdd',
        method:'post',
        data:a
    })
    .then((res)=>{
    console.log(res);
    if(res.data==-1)
    {
        alert("名称重复");
        return;
    }
    if(res.data>0)
    {
        alert("添加成功");
        router.push("/houseshow");
    }
})
}

</script>

<style scoped></style>